package com.ruoyi.system.controller;

import java.util.ArrayList;
import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.QJiankong;
import com.ruoyi.system.service.IQJiankongService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 当日监控数字统计Controller
 * 
 * @author ruoyi
 * @date 2024-07-16
 */
@Controller
@RequestMapping("/system/jiankong")
public class QJiankongController extends BaseController
{
    private String prefix = "system/jiankong";

    @Autowired
    private IQJiankongService qJiankongService;

    @RequiresPermissions("system:jiankong:view")
    @GetMapping()
    public String jiankong()
    {
        return prefix + "/jiankong";
    }

    /**
     * 查询当日监控数字统计列表
     */
    @RequiresPermissions("system:jiankong:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(QJiankong qJiankong)
    {
        startPage();
        List<QJiankong> list = new ArrayList<QJiankong>() ;
        QJiankong tmp = new QJiankong();
        tmp.setHuruliang(String.valueOf(qJiankongService.selectHrl(qJiankong)));
        tmp.setJietingliang(String.valueOf(qJiankongService.selectJtl(qJiankong)));
        tmp.setHuchuliang(String.valueOf(qJiankongService.selectHrlOut(qJiankong)));
        tmp.setHuchujt(String.valueOf(qJiankongService.selectJtlOut(qJiankong)));

        list.add(tmp);
        return getDataTable(list);
    }

    /**
     * 查询当日IM数字统计列表
     */
    @RequiresPermissions("system:jiankong:list")
    @PostMapping("/listIM")
    @ResponseBody
    public TableDataInfo listIM(QJiankong qJiankong)
    {
        startPage();
        List<QJiankong> list = new ArrayList<QJiankong>() ;
        QJiankong tmp = new QJiankong();
        tmp.setHuruliang(String.valueOf(qJiankongService.selectHrlIM(qJiankong)));
        tmp.setJietingliang(String.valueOf(qJiankongService.selectJtlIM(qJiankong)));

        tmp.setHuchuliang(String.valueOf(qJiankongService.selectHrlOutIM(qJiankong)));
        tmp.setHuchujt(String.valueOf(qJiankongService.selectJtlOutIM(qJiankong)));

        list.add(tmp);
        return getDataTable(list);
    }

    /**
     * 导出当日监控数字统计列表
     */
    @RequiresPermissions("system:jiankong:export")
    @Log(title = "当日监控数字统计", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(QJiankong qJiankong)
    {
        List<QJiankong> list = qJiankongService.selectQJiankongList(qJiankong);
        ExcelUtil<QJiankong> util = new ExcelUtil<QJiankong>(QJiankong.class);
        return util.exportExcel(list, "当日监控数字统计数据");
    }

    /**
     * 新增当日监控数字统计
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存当日监控数字统计
     */
    @RequiresPermissions("system:jiankong:add")
    @Log(title = "当日监控数字统计", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(QJiankong qJiankong)
    {
        return toAjax(qJiankongService.insertQJiankong(qJiankong));
    }

    /**
     * 修改当日监控数字统计
     */
    @RequiresPermissions("system:jiankong:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        QJiankong qJiankong = qJiankongService.selectQJiankongById(id);
        mmap.put("qJiankong", qJiankong);
        return prefix + "/edit";
    }

    /**
     * 修改保存当日监控数字统计
     */
    @RequiresPermissions("system:jiankong:edit")
    @Log(title = "当日监控数字统计", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(QJiankong qJiankong)
    {
        return toAjax(qJiankongService.updateQJiankong(qJiankong));
    }

    /**
     * 删除当日监控数字统计
     */
    @RequiresPermissions("system:jiankong:remove")
    @Log(title = "当日监控数字统计", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(qJiankongService.deleteQJiankongByIds(ids));
    }
}
